import Vue from "vue";
import VueRouter from "vue-router";
import { getItem } from "@/utils/storage.js";

Vue.use(VueRouter);

const routes = [
  // 登录页路由
  {
    path: "/login",
    // 设置路由的名称，命名路由。
    name: "login",
    component: () => import("@/views/login"),
  },
  // 配置页面组件布局路由
  {
    path: "/",
    // redirect: "/home",
    component: () => import("@/views/layout"),
    children: [
      {
        path: "",
        // path: "/home",
        name: "home",
        component: () => import("@/views/home"),
        // 首页tab项切换
        meta: {
          page: getItem("TOUTIAO_PAGE") ? getItem("TOUTIAO_PAGE") : null,
        },
      },
      {
        path: "qa",
        name: "qa",
        component: () => import("@/views/qa"),
      },
      {
        path: "video",
        name: "video",
        component: () => import("@/views/video"),
      },
      {
        path: "my",
        name: "my",
        component: () => import("@/views/my"),
      },
    ],
  },
  // 搜索页面的路由配置到根组件路由（一级路由）
  {
    //注意这里path要加/;上面四个页面不加是因为layout统一配置了; path: "/search",
    path: "/search",
    name: "search",
    component: () => import("@/views/search"),
  },
  // 文章详情(动态路由参数参数)
  {
    path: "/article/:articleId",
    name: "article",
    component: () => import("@/views/article"),
    // 开启 props 传参，说白了就是把路由参数映射到组件的 props 中
    props: true,
  },
  // 个人中心
  {
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile')
  }
];

const router = new VueRouter({
  routes,
});

export default router;
